package thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Ticket2 implements Runnable {
	int ticket=100;
	Lock lo=new ReentrantLock();
	
	@Override
	public void run() {
		while(true){
			if(ticket==0){
				System.out.println("票卖完了");
				break;
		}
			lo.lock();
			if(ticket>0){
				try {
					Thread.sleep(1);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println(Thread.currentThread().getName()+"正在运行"+ticket);
			}
			lo.unlock();
	}

	
	
}
	}